import request from './request.js'

export function register(data) {
  return request({
    url: '/user/register',
    method: 'post',
    data
  })
}

export function login(username, password) {
  return request({
    url: '/user/login',
    method: 'post',
    data: { username, password }
  });
}

export function getUser(id) {
  return request({
    url: `/user/${id}`,
    method: 'get'
  });
}

export function updateUserProfile(data) {
  return request({
    url: '/user/profile',
    method: 'put',
    data
  });
}

export function uploadAvatar(file, userId) {
  const formData = new FormData();
  formData.append('file', file);
  formData.append('userId', userId);
  return request({
    url: '/user/uploadAvatar',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
}